package HelperFinancial.DataBase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import HelperFinancial.User.DebitoActivity;
import android.content.Context;

public class GraphicDataAdapter {
	private DebitoAdapter debitos;
	
	public GraphicDataAdapter(Context context){
		debitos = DebitoAdapter.getInstance(context);
	}
	
	public double getSumOfDebits(){
		return debitos.getDebitsSumToGraphic();
	}
	
	public List<String> getAllValidTypesOfDebits(){
		List<String> list = new ArrayList<String>();
		Map<String, String> mapDebit = debitos.getDebitsByTypeToGraphic();
		Iterator<String> allDebits = mapDebit.keySet().iterator();
		while(allDebits.hasNext()){
			list.add(allDebits.next());
		}
		return list;
	}
	
	public Map<String,String> getMapTypeToValue(){
		return debitos.getDebitsByTypeToGraphic();
	}
	
	public Map<String,Double> getMapTypeToPercent(){
		Map map = new HashMap<String, Double>();
		List<String> types = getAllValidTypesOfDebits();
		Map<String, String> value = getMapTypeToValue();
		for (int i = 0; i < types.size(); i++) {
			map.put(types.get(i), (Double.parseDouble(value.get(types.get(i)))/getSumOfDebits())*100);
		}
		
		return map;
	}
	
	public List<Integer> getValues(){
		List<Integer> list = new ArrayList<Integer>();
		Map<String, Double> mapDebit = getMapTypeToPercent();
		Iterator<Double> allValues = mapDebit.values().iterator();
		while(allValues.hasNext()){
			list.add((int) Math.floor(allValues.next()));
		}
		return list;
	}
}
